package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 分页查询护理项目
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> queryPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingProjectVo> page = nursingProjectMapper.selectPageNursing(name,status);
        return PageResponse.of(page,NursingProjectVo.class);
    }

    /**
     * 添加护理项目
     * @param nursingProjectDto
     */
    @Override
    public void addNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProject.setCreateBy(1L);
        nursingProject.setCreateTime(LocalDateTime.now());

        nursingProjectMapper.insertNursingProject(nursingProject);
    }

    /**
     * 根据id查询护理项目
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getNursingProjectById(Integer id) {
        return nursingProjectMapper.selectNursingProjectById(id);
    }

    /**
     * 修改护理项目
     * @param nursingProjectDto
     */
    @Override
    public void updateNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProject.setUpdateBy(1L);
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProjectMapper.updateNursingProject(nursingProject);

    }

    /**
     * 启用禁用
     * @param id
     * @param status
     */
    @Override
    public void updateStatusById(Integer id, Integer status) {
        nursingProjectMapper.updateStatusById(id,status);
    }

    /**
     * 根据id删除护理项目
     * @param id
     */
    @Override
    public void deleteNursingProjectById(Integer id) {
        nursingProjectMapper.deleteNursingProjxectById(id);
    }

    /**
     * 查询所有护理项目
     * @return
     */
    @Override
    public List<NursingProjectVo> showAllNursingProject() {
        return nursingProjectMapper.showAllNursingProject();
    }


}
